// 收货地址持久化

import { getAddressList, setDefaultAddress } from '@/api/address'
export default ({
  namespaced: true,
  state: {
    // 收货地址列表
    addressList: [],
    // 默认地址id
    defaultAddress: null
  },
  mutations: {
    // 设置地址列表
    setAddressList (state, addressList) {
      state.addressList = addressList
    },
    // 设置默认地址
    setDefaultAddress (state, defaultAddress) {
      state.defaultAddress = defaultAddress
    }
  },
  actions: {
    // 获取地址列表
    async getAddressList (context) {
      const res = await getAddressList()
      context.commit('setAddressList', res.data.list)
      // console.log(res)
    },
    // 设置默认地址
    async setDefaultAddress (context) {
      const { data: { defaultId } } = await setDefaultAddress()
      context.commit('setDefaultAddress', defaultId)
      // console.log(res)
    }
  },
  getters: {
  }

})
